/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */


package ru.teleology.cubefs.api.reflection;

import java.util.ArrayList;

import ru.teleology.cubefs.api.exceptions.BoundsException;
import ru.teleology.cubefs.api.exceptions.CubefsException;
import ru.teleology.cubefs.api.exceptions.DispatchException;
import ru.teleology.cubefs.api.exceptions.TypeCastException;

public class Factory extends TypeSystem {
		
	public static Long newLong(long value) {
		return new Long(value);
	}
	
	@SuppressWarnings("unchecked")
	public static Class getListClass() {
		return ArrayList.class;
	}
	
	@SuppressWarnings("unchecked")
	public static Class getCoreExceptionClass() {
		return CubefsException.class;
	}
	
	@SuppressWarnings("unchecked")
	public static java.util.List newList() {
		return new ArrayList();
	}
	
	public static void throwCubefsException(String source, String msg, long data) {
		throw new CubefsException(source, msg + " data="+data);
	}
	
	public static void throwBoundsException(String source, String msg, long index, long index1, long index2) {
		throw new BoundsException(source, msg, index, index1, index2);
	}
	
	public static void throwNullPointerException(String source, String msg) {
		throw new NullPointerException(source +" - "+ msg);
	}
	
	public static void throwTypeCastException(String source, String msg, long srctype, long tgttype) {
		Type src = (Type) Typed.peer(srctype);
		if (src == null) {
			src = new Type(srctype);
		}
		
		Type tgt = (Type) Typed.peer(tgttype);
		if (tgt == null) {
			tgt = new Type(tgttype);
		}
		
		throw new TypeCastException(source, msg, src, tgt);
	}
	
	public static void throwDispatchException(String source, String msg, int code1, int code2) {
		throw new DispatchException(source, msg, code1, code2);
	}
}
